# 接收邮件
import poplib
import email.parser, email.policy

conn = poplib.POP3_SSL('pop.qq.com', 995)
conn.user('1769699920@qq.com')
# 授权码
conn.pass_('oylloweejozkbifa')
res, maillist, r = conn.list()
print('响应 ', res)
print('邮件列表 ', maillist)

# 4、遍历邮件
# msg = email.parser.BytesParser(policy=email.policy.default).parsebytes(data)
# for part in msg.walk():
#     # multipart 代表邮件内容的容器，无需处理
#     if part.get_content_type().split("/", 1)[0] == 'multipart':
#         continue
#     elif part.get_content_type().split("/", 1)[0] == 'text':
#         print(part.get_content())
#     else:
#         filename = part.get_filename()
#         print(filename)
#         with open(filename, 'wb') as f:
#             f.write(part.get_payload(decode=True))

# 退出
conn.quit()
